package com.mxin.ui.widget.dialog.loading

import android.app.Dialog
import android.content.Context
import android.view.WindowManager
import android.widget.TextView
import androidx.annotation.StyleRes
import com.mxin.ui.R
import com.mxin.util.ScreenUtils
import com.wang.avi.AVLoadingIndicatorView


class LoadingDialog(context: Context, @StyleRes themeResId:Int) :Dialog(context, themeResId) {


    class Builder(private val context: Context){

        fun create(): LoadingDialog {
            val dialog = LoadingDialog(context, R.style.Dialog)
            dialog.setContentView(R.layout.ui_dialog_loading_view)
            dialog.setCanceledOnTouchOutside(false) // 设置点击屏幕Dialog不消失
            val window = dialog.window!!
            val lp: WindowManager.LayoutParams = window.getAttributes()
            val screenW: Int = ScreenUtils.getScreenWidth()
            lp.width = (0.6 * screenW).toInt()
            val titleTxtv = dialog.findViewById<TextView>(R.id.tv_load)
            titleTxtv.text = "努力加载中..."
            return dialog
        }

        fun createIndicator(): LoadingDialog {
            val dialog = LoadingDialog(context, R.style.Dialog)
            dialog.setContentView(R.layout.ui_dialog_loading_indicator_view)
            dialog.setCanceledOnTouchOutside(false) // 设置点击屏幕Dialog不消失
            val indicatorView = dialog.findViewById<AVLoadingIndicatorView>(R.id.avi)
            dialog.setOnShowListener {  indicatorView.show()}
            dialog.setOnDismissListener { indicatorView.hide() }
            return dialog
        }

    }




}